home *** CD-ROM | disk | FTP | other *** search
-
- /* This program is supposed to draw "Mandelbrot" shapes that resemble */
- /* mountains. This is done by starting with a triangle figure and */
- /* successively subdividing (randomly spaced) the sides. These points */
- /* are then joined to form four smaller triangles within the original */
- /* one. The process is repeated for each of these four triangles and */
- /* onto the next step of transformation..... */
-
- /* Original Pascal program written by: John O'Neill */
- /* Translated to C for the Atari ST by: Bob Ritter (Nov. 1985) */
-
- #include <osbind.h>
-
- #define NUMSTEPS 7 /* too bad...any more and kabombs */
- #define SCALE 0.22
- #define PI2 6.2631853
-
- extern float sqrt(), sin(), cos(), random();
-
- int contrl[12], intin[128], ptsin[128], intout[128], ptsout[128];
- int i, handle, dummy;
- int xy[8], GoLeft;
- int numtrees;
- float c;
- char cc[5], line[80] = "Step: Number of points: ";
-
- struct tree
- {
- int locx;
- int locy;
- int left; /* "*struct" tree would be more sophisticated, and */
- int right; /* then would use "Malloc(sizeof(struct tree))". */
- } root[5000]; /* 5K should be 'nuf - not being a fancy man */
-
-
- main()
- {
- int step;
- setup();
- GoLeft = 1;
- display(0);
- for (step = 2; step <= NUMSTEPS; ++step)
- {
- GoLeft = 1;
- c = numtrees;
- transform(0);
- GoLeft = 1;
- v_clrwk(handle);
- c = step;
- ftoa(c,cc,0);
- line[6] = cc[0]; /* that's a mess Bob */
- c = numtrees + 1;
- ftoa(c,cc,0);
- line[35] = cc[4];
- line[34] = cc[3];
- line[33] = cc[2];
- line[32] = cc[1];
- line[31] = cc[0]; /* admitably this is a mess too */
- v_gtext(handle,75,15,line);
- display(0);
- Cconin(); /*This should really be "evnt_keybd();" - but for GemBug!! */
- }
- }
-
- setup()
- {
- int mx1, my1, mx2, my2, mx3, my3;
-
- /* Set the system up to do GEM calls*/
- appl_init();
-
- /* Get the handle of the desktop */
- handle=graf_handle(&dummy,&dummy,&dummy,&dummy);
-
- /* Open the workstation. */
- for (i=0; i<10; intin[i++] = 1);
- intin[10] = 2;
- v_opnvwk(intin, &handle, intout);
-
- graf_mouse(256,&dummy);
- v_clrwk(handle);
- graf_mouse(257,&dummy);
- graf_mouse(5,&dummy);
-
- v_gtext(handle,15,15,"Click the mouse on the 3 starting co-ordinates.");
- evnt_button(1,1,1,&mx1,&my1,&dummy,&dummy);
- xy[0] = mx1;
- xy[1] = my1;
- xy[6] = mx1;
- xy[7] = my1;
- evnt_button(1,1,1,&mx2,&my2,&dummy,&dummy);
- xy[2] = mx2;
- xy[3] = my2;
- v_pline(handle,2,xy);
- evnt_button(1,1,1,&mx3,&my3,&dummy,&dummy);
- xy[4] = mx3;
- xy[5] = my3;
- v_pline(handle,4,xy);
-
- graf_mouse(256,&dummy);
-
- numtrees = 2; /* well, really it's one more... */
- root[0].left = 1;
- root[0].right = 2;
- root[1].left = 0;
- root[1].right = 0;
- root[2].left = 0;
- root[2].right = 0;
- root[0].locx = mx1;
- root[0].locy = my1;
- root[1].locx = mx2;
- root[1].locy = my2;
- root[2].locx = mx3;
- root[2].locy = my3;
- }
-
- midpoint(mp,x1,y1,x2,y2)
- int mp, x1, x2, y1, y2;
- {
- float dx, dy;
- double length, radius, angle;
- dx = x2 - x1;
- dy = y2 - y1;
- length = sqrt(dx * dx + dy * dy);
- radius = length * SCALE * (Random() & 100) / 100;
- angle = PI2 * (Random() & 100) / 100;
- root[mp].locx = (x1 + x2)/2 + cos(angle) * radius;
- root[mp].locy = (y1 + y2)/2 + sin(angle) * radius;
- }
-
- transform(node)
- int node;
- {
- if (GoLeft && (root[root[node].left].left != 0))
- transform(root[node].left);
- GoLeft = 0;
- if (root[root[node].right].right != 0)
- transform(root[node].right);
- ftoa(c,cc,0);
- cc[9] = '\0';
- v_gtext(handle,30,30,cc);
- --c;
- midpoint(numtrees + 1,root[node].locx,root[node].locy,
- root[root[node].left].locx,root[root[node].left].locy);
- midpoint(numtrees + 2,root[root[node].left].locx,
- root[root[node].left].locy,
- root[root[node].right].locx,root[root[node].right].locy);
- midpoint(numtrees + 3,root[node].locx,root[node].locy,
- root[root[node].right].locx,root[root[node].right].locy);
- root[numtrees + 1].left = root[node].left;
- root[numtrees + 1].right = numtrees + 2;
- root[numtrees + 3].left = numtrees + 2;
- root[numtrees + 3].right = root[node].right;
- root[numtrees + 2].left = root[root[node].left].right;
- root[numtrees + 2].right = root[root[node].right].left;
- root[node].left = numtrees + 1;
- root[node].right = numtrees + 3;
- numtrees = numtrees + 3;
- }
-
- display(node)
- int node;
- {
- if (GoLeft && (root[root[node].left].left != 0))
- display(root[node].left);
- GoLeft = 0;
- if (root[root[node].right].right != 0)
- display(root[node].right);
- xy[0] = root[node].locx;
- xy[1] = root[node].locy;
- xy[2] = root[root[node].left].locx;
- xy[3] = root[root[node].left].locy;
- xy[4] = root[root[node].right].locx;
- xy[5] = root[root[node].right].locy;
- xy[6] = xy[0];
- xy[7] = xy[1];
- v_pline(handle,4,xy);
- }